//
//  SEGPersonalHomePagCell.m
//  FrameworkTest
//
//  Created by 梁昆 on 2018/4/20.
//  Copyright © 2018年 刘山. All rights reserved.
//

#import "SEGPersonalHomePagCell.h"
@interface SEGPersonalHomePagCell() <SEGCustomContentViewDelegate,SEGTopicTextViewDelegate,SEGTopicPicViewDelegate, SEGprotocolFocusViewDelegate>
@end

@implementation SEGPersonalHomePagCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    [self.contentView addSubview:self.wholeCell];
    self.line=[UIView new];
    self.line.backgroundColor=kColor_L2;
    self.line.frame=CGRectMake(CGRectGetMaxX(self.contentView.frame), CGRectGetMaxY(self.contentView.frame)-0.5, self.wholeCell.frame.size.width, 0.5);
    [self.contentView addSubview:self.line];
    
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    self.wholeCell.userInteractionEnabled = YES;
    self.wholeCell.customContentView.userInteractionEnabled = YES;
    
    //集市，看点内容点击 代理
    self.wholeCell.customContentView.delegate = self;
    //文本，话题标签 代理
    self.wholeCell.customContentView.topicTextView.delegate = self;
    //图文，话题标签 代理
    self.wholeCell.customContentView.topicPicView.delegate = self;
    //邻里圈，图片点击 代理
    self.wholeCell.customContentView.neighbourView.delegate = self;
    //转发PGC 代理
    self.wholeCell.customContentView.focusView.delegate = self;
    return self;
}

- (void)setLayout:(SEGCustomWholeViewLayout *)layout isFirstCell:(BOOL)isFirstCell
{
    CGFloat topPadding = 0;
    if (isFirstCell) {//第一条数据顶部间距多5
        topPadding = 5;
    }
    self.height = layout.totalHeight + topPadding;
    self.contentView.height = layout.totalHeight + topPadding;
    
    self.wholeCell.frame = CGRectMake(0, topPadding, self.wholeCell.frame.size.width, self.wholeCell.frame.size.height);
    
    [self.wholeCell setWithLayout:layout];
    self.line.frame=CGRectMake(70, self.contentView.height-0.5, self.wholeCell.frame.size.width, 0.5);
    //    self.contentView.backgroundColor = kSegRandomColor;
}

#pragma mark - SEGCustomContentViewDelegate 内容视图点击代理方法
//点击集市内容
-(void)customContentViewMarketView:(SEGMarketView*)view{
    if (self.delegate && [self.delegate respondsToSelector:@selector(personalCellMarketTapWithIndexPath:)]) {
        [self.delegate personalCellMarketTapWithIndexPath:self.indexPath];
    }
    
}

#pragma mark - SEGTopicPicViewDelegate 图文话题点击代理方法
//图文话题，点击话题标签
-(void)topicPicViewTitleLabel:(SEGLabel*)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(personalCellTopicTagetTapWithIndexPath:)]) {
        [self.delegate personalCellTopicTagetTapWithIndexPath:self.indexPath];
    }
}

//图文话题 点击图片
-(void)topicPicViewPicTap:(NSArray *)imageUrlStrArray imageView:(UIImageView *)imageView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(personalCellTapWithIndexPath:)]) {
        [self.delegate personalCellTapWithIndexPath:self.indexPath];
    }
}

#pragma mark - SEGTopicTextViewDelegate 文字话题，标签点击代理方法
//文字话题，标签点击代理方法
-(void)topicTextTopicTitleLabel:(SEGLabel*)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(personalCellTopicTagetTapWithIndexPath:)]) {
        [self.delegate personalCellTopicTagetTapWithIndexPath:self.indexPath];
    }
}

#pragma mark - SEGprotocolNeighbourViewDelegate  邻里圈，图片点击 代理
- (void)neighbourViewImageTapWithImageUrlArray:(NSArray *)arr SelectedImageView:(UIImageView *)image SelectedIndex:(NSInteger)index
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(personalCellTapWithIndexPath:)]) {
        [self.delegate personalCellTapWithIndexPath:self.indexPath];
    }
}

#pragma mark - SEGprotocolFocusViewDelegate
//点击PGC处理
-(void)focusPGCContentViewTap
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(personalCellFocusTapWithIndexPath:)]) {
        [self.delegate personalCellFocusTapWithIndexPath:self.indexPath];
    }
}

-(void)focusChannelNameLabelTap:(SEGLabel*)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(personalCellFocusChannelNameTapWithIndexPath:)]) {
        [self.delegate personalCellFocusChannelNameTapWithIndexPath:self.indexPath];
    }
}

#pragma mark - getter
-(SEGCustomWholeView *)wholeCell{
    if (!_wholeCell) {
        _wholeCell = [[SEGCustomWholeView alloc]initWithFrame:CGRectZero];
    }
    return _wholeCell;
}

@end
